package com.hugo.educms.controller;


import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.hugo.commonutiles.R;
import com.hugo.educms.entity.CrmBanner;
import com.hugo.educms.service.CrmBannerService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

/**
 * <p>
 * 首页banner表 后台控制器
 * </p>
 *
 * @author hugo
 * @since 2020-09-16
 */
@RestController
@RequestMapping("/educms/bannerAdmin")
@CrossOrigin
public class BannerAdminController {
    @Autowired
    private CrmBannerService crmBannerService;
    //分页查询banner功能
    @GetMapping("pageBanner/{page}/{limit}")
    public R pageBanner(@PathVariable long page,@PathVariable long limit){
        Page<CrmBanner> bannerPage=new Page<>(page,limit);
        crmBannerService.page(bannerPage,null);
        long total=bannerPage.getTotal();
        return R.ok().data("total",total).data("litems",bannerPage.getRecords());
    }
    //添加banner功能
    @PostMapping("addBanner")
    public R addBanner(@RequestBody CrmBanner crmBanner){
        crmBannerService.save(crmBanner);
        return R.ok();
    }
    //删
    @DeleteMapping("deleteBanner/{id}")
    public R deleteBanner(@PathVariable String id){
        crmBannerService.removeById(id);
        return R.ok();
    }
    //改
    @PostMapping("updateBanner/{id}")
    public R updateBanner(@RequestBody CrmBanner crmBanner){
        crmBannerService.updateById(crmBanner);
        return R.ok();

    }
    //查
    @GetMapping("getBanner/{id}")
    public R getBanner(@PathVariable String id){
        crmBannerService.getById(id);
        return R.ok();

    }
}

